package com.codi.fcloud.ufx.hssale.query;

import com.codi.base.log.annotation.Loggable;
import com.codi.base.util.ExceptionUtil;
import com.codi.bus.exception.HundsunAPIException;
import com.codi.fcloud.ufx.UfxSDKFactory;
import com.codi.fcloud.ufx.constant.HSInputParameterNames;
import com.codi.fcloud.ufx.constant.UrlConstants;
import com.codi.trade.dto.AccountApplyQryDto;
import com.codi.trade.service.AccountApplyQryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 账户申请查询
 *
 * @author shi.pengyan
 * @version 1.0 2017-09-05 17:01
 * @since 1.0
 */
@Slf4j
@Service("accountApplyQryService")
public class AccountApplyQuery extends UfxSDKFactory implements AccountApplyQryService {
    @Override
    public Map<String, Object> query(String clientId) {
        AccountApplyQryDto dto = new AccountApplyQryDto();
        dto.setClient_id(clientId);

        return query(dto);
    }

    @Override
    @Loggable
    public Map<String, Object> query(AccountApplyQryDto dto) {

        String trustWay = apiValueMap.get(HSInputParameterNames.TRUST_WAY);

        Map<String, Object> request = new HashMap<String, Object>();


//        private String net_no;          //	C9	网点代码	N	不传则使用默认值"0001" ，有传值（包括空）则使用所传值
//        private String request_num;     //	N10	请求行数	Y	最大不能超过50；即最大返回记录条数不会超过50条；
//        private String reqry_recordsum_flag;//	N10	重新统计总记录数标志	Y	0-不重新统计；1-重新统计；
//        private String qry_beginrownum; //	N10	查询起始行号	Y	比如总记录是100，每50条分页；那么需要查询2次；第1次查询请求行数传50，重新统计总记录数传1，查询起始private String 行号传1；第2次查询请求行数传50，重新统计总记录数传0，查询起始行号传51；
//        private String ta_acco;         //	C12	TA账号	N
//        private String client_id;       //	C18	客户编号	N	客户编号、申请编号至少有一个为必填项


        request.put("trust_way", trustWay);
        request.put("net_no", getString(dto.getNet_no(), "0001"));
        request.put("request_num", getString(dto.getRequest_num(), "50"));
        request.put("reqry_recordsum_flag", getString(dto.getReqry_recordsum_flag(), "1"));
        request.put("qry_beginrownum", getString(dto.getQry_beginrownum(), "0"));
        request.put("ta_acco", getString(dto.getTa_acco()));
        request.put("client_id", getString(dto.getClient_id()));
        request.put("fund_busin_code", getString(dto.getFund_busin_code()));  //	C3	业务代码	N
        request.put("begin_date", getString(dto.getBegin_date()));//	C8	起始日期	N
        request.put("end_date", getString(dto.getEnd_date()));//	C8	到期日期	N
        request.put("allot_no", getString(dto.getAllot_no()));//	C24	申请编号	N
        request.put("trade_source", getString(dto.getTrade_source()));//	C12	交易来源	N
        request.put("taconfirm_flag", getString(dto.getTaconfirm_flag()));//	C1	确认标志	N
        request.put("busin_ass_code", getString(dto.getBusin_ass_code()));//	C2	业务辅助代码	N
        request.put("sort_direction", getString(dto.getSort_direction()));//	C1	返回排序方式	N

        try {
            //
            List<Map<String, Object>> response = getUfxSDK().query(getTarget(), request);

            return appendLog(request, response);
        } catch (Exception exception) {
            ExceptionUtil.logError(logger, getTarget(), exception);
            throw new HundsunAPIException(ExceptionUtil.getMessage(exception));
        }
    }

    @Override
    protected String getTarget() {
        return UrlConstants.PREFIX_SALE + UrlConstants.ACCOUNT_APPLY_QRY;
    }
}
